package com.gxstnu.controller;

import com.gxstnu.common.Result;
import com.gxstnu.entity.ChatMessage;
import com.gxstnu.service.AIService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ai")
public class AIController {

    @Resource
    private AIService aiService;

    /**
     * 发送问题到AI并获取回答
     */
    @PostMapping("/chat")
    public Result chat(@RequestBody Map<String, String> params) {
        String question = params.get("question");
        String answer = aiService.getAIResponse(question);
        return Result.success(Map.of("answer", answer));
    }

    /**
     * 获取历史对话记录
     */
    @GetMapping("/history")
    public Result getHistory() {
        List<ChatMessage> history = aiService.getChatHistory();
        return Result.success(history);
    }
}